<?php

class ClassLoader {
	public static function loader($classname) {
		
		if( substr($classname, -5) ==  "Model" ){
			$filename = MODEL_PATH . $classname.".php";
		} else if( substr($classname, -10) == "Controller") {
			$filename = CONTROL_PATH . $classname.".php";
		} else if( substr($classname, -6) == "Driver") {
			$filename = DRIVER_PATH . substr($classname, 0, strlen($classname)-6) .
			'/'.  $classname . ".php";
		} else if ( substr($classname, -6) == "Server") {
			$filename = SERVER_PATH . $classname . ".php";
		} else {
			return ;
		}
		
		try{ 
			require_once($filename);
		} catch(Exception $e) {
			echo "autoload failed ".$classname." with path:".$filename;
		}
	}
}
spl_autoload_register('ClassLoader::loader');

?>